package com.ruoyi.ucar.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.ucar.boreq.RechargeRecordDetailQueryBoReq;
import com.ruoyi.ucar.boreq.RechargeRecordListQueryBoReq;
import com.ruoyi.ucar.boresp.RechargeRecordDetailQueryBoResp;
import com.ruoyi.ucar.boresp.RechargeRecordListQueryBoResp;
import com.ruoyi.ucar.common.CommonVoResp;
import com.ruoyi.ucar.service.ITRechargeRecordService;
import com.ruoyi.ucar.domain.TRechargeRecord;
import com.ruoyi.ucar.util.CommonUtil;
import com.ruoyi.ucar.voreq.RechargeRecordDetailQueryVoReq;
import com.ruoyi.ucar.voreq.RechargeRecordListQueryVoReq;
import com.ruoyi.ucar.voresp.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 充值记录Controller
 * 
 * @author sungangbin
 * @date 2025-05-13
 */
@Api(value = "充值记录管理",tags = "充值记录管理模块接口")
@RestController
@RequestMapping("/ucar/RechargeRecord")
public class  TRechargeRecordController extends BaseController
{
    @Autowired
    private ITRechargeRecordService tRechargeRecordService;

    /**
     * 查询充值记录列表
     */
    @ApiOperation("充值记录列表")
    @PreAuthorize("@ss.hasPermi('ucar:RechargeRecord:list')")
    @PostMapping("/list")
    public CommonVoResp<RechargeRecordListQueryVoResp> list(@RequestBody RechargeRecordListQueryVoReq rechargeRecordListQueryVoReq)
    {
        logger.info("  充值记录列表查询VO端入口参数:{}",rechargeRecordListQueryVoReq);
        CommonVoResp<RechargeRecordListQueryVoResp> commonVoResp=new CommonVoResp<>();
        if(
                rechargeRecordListQueryVoReq.getPageIndex()==null||
                        rechargeRecordListQueryVoReq.getPageSize()==null){
            return CommonUtil.setCommonVoRespNoParam(commonVoResp);
        }
        RechargeRecordListQueryBoReq rechargeRecordListQueryBoReq=CommonUtil.objToObj(rechargeRecordListQueryVoReq, RechargeRecordListQueryBoReq.class);
        rechargeRecordListQueryBoReq.setPageIndex(rechargeRecordListQueryVoReq.getPageIndex());
        rechargeRecordListQueryBoReq.setPageSize(rechargeRecordListQueryVoReq.getPageSize());
        RechargeRecordListQueryBoResp rechargeRecordListQueryBoResp=tRechargeRecordService.queryRechargeRecordList(rechargeRecordListQueryBoReq);
        if(StringUtils.isNotNull(rechargeRecordListQueryBoResp)){
            RechargeRecordListQueryVoResp rechargeRecordListQueryVoResp=new RechargeRecordListQueryVoResp();
            List<RechargeRecordListQueryVo> rechargeRecordListQueryVos=new ArrayList<>();
            rechargeRecordListQueryVoResp.setTotalCount(rechargeRecordListQueryBoResp.getTotalCount());
            rechargeRecordListQueryVoResp.setTotalPage(rechargeRecordListQueryBoResp.getTotalPage());
            rechargeRecordListQueryBoResp.getRechargeRecordListQueryBos().forEach(rechargeRecordListQueryBo -> {
                RechargeRecordListQueryVo rechargeRecordListQueryVo=CommonUtil.objToObj(rechargeRecordListQueryBo, RechargeRecordListQueryVo.class);
                rechargeRecordListQueryVos.add(rechargeRecordListQueryVo);
            });
            rechargeRecordListQueryVoResp.setRechargeRecordListQueryVos(rechargeRecordListQueryVos);
            commonVoResp.setData(rechargeRecordListQueryVoResp);
        }else{
            return CommonUtil.setCommonVoRespNoDataError(commonVoResp);
        }
        logger.info("充值记录列表查询出参：{}",commonVoResp);
        return commonVoResp;
    }

    /**
     * 导出充值记录列表
     */
    @PreAuthorize("@ss.hasPermi('ucar:RechargeRecord:export')")
    @Log(title = "充值记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRechargeRecord tRechargeRecord)
    {
        List<TRechargeRecord> list = tRechargeRecordService.selectTRechargeRecordList(tRechargeRecord);
        ExcelUtil<TRechargeRecord> util = new ExcelUtil<TRechargeRecord>(TRechargeRecord.class);
        util.exportExcel(response, list, "充值记录数据");
    }

    /**
     * 获取充值记录详细信息
     */
    @ApiOperation("获取充值记录详细信息-id和rechargeRecordUuid，两者传一即可")
    @PreAuthorize("@ss.hasPermi('ucar:RechargeRecord:query')")
    @PostMapping(value = "/detail")
    public CommonVoResp<RechargeRecordDetailQueryVoResp> rechargeRecordDetail(@RequestBody RechargeRecordDetailQueryVoReq rechargeRecordDetailQueryVoReq)
    {
        CommonVoResp<RechargeRecordDetailQueryVoResp> commonVoResp=new CommonVoResp<>();
        logger.info("获取充值记录详细信息入参：{}",rechargeRecordDetailQueryVoReq);
        if(
                rechargeRecordDetailQueryVoReq.getRechargeRecordUuid()==null&&
                        rechargeRecordDetailQueryVoReq.getId()==null){
            return CommonUtil.setCommonVoRespNoParam(commonVoResp);
        }
        RechargeRecordDetailQueryBoResp rechargeRecordDetailQueryBoResp=tRechargeRecordService.rechargeRecordDetail(CommonUtil.objToObj(rechargeRecordDetailQueryVoReq, RechargeRecordDetailQueryBoReq.class));

        if(StringUtils.isNull(rechargeRecordDetailQueryBoResp)){
            return CommonUtil.setCommonVoRespNoDataError(commonVoResp);
        }else{
            RechargeRecordDetailQueryVoResp rechargeRecordDetailQueryVoResp=CommonUtil.objToObj(rechargeRecordDetailQueryBoResp,RechargeRecordDetailQueryVoResp.class);
            commonVoResp.setData(rechargeRecordDetailQueryVoResp);
        }
        logger.info("获取充值记录详细信息出参：{}",commonVoResp);
        return commonVoResp;
    }

    /**
     * 新增充值记录
     */
    @PreAuthorize("@ss.hasPermi('ucar:RechargeRecord:add')")
    @Log(title = "充值记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRechargeRecord tRechargeRecord)
    {
        return toAjax(tRechargeRecordService.insertTRechargeRecord(tRechargeRecord));
    }

    /**
     * 修改充值记录
     */
    @PreAuthorize("@ss.hasPermi('ucar:RechargeRecord:edit')")
    @Log(title = "充值记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRechargeRecord tRechargeRecord)
    {
        return toAjax(tRechargeRecordService.updateTRechargeRecord(tRechargeRecord));
    }

    /**
     * 删除充值记录
     */
    @PreAuthorize("@ss.hasPermi('ucar:RechargeRecord:remove')")
    @Log(title = "充值记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tRechargeRecordService.deleteTRechargeRecordByIds(ids));
    }
}
